package com.demo.java.netty.pipeline;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;

import java.nio.charset.Charset;

public class OutboundHandler2 extends ChannelOutboundHandlerAdapter {
    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
        ByteBuf buf = (ByteBuf) msg;
        System.out.println("channel write outbound2, write msg: " + buf.toString(Charset.defaultCharset()));

        ctx.write(Unpooled.copiedBuffer(buf.toString(Charset.defaultCharset()), Charset.defaultCharset()));
        ctx.flush();
    }
}
